/*
 * Copyright (C) 2010 Raimundo Mirisola (raimundo.mirisola@gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */


package com.onerm.ui;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class PanelBuilder {

  public static View createList(Activity activity, ListAdapter adapter) {

    // create the ui components
    LinearLayout mainpanel = new LinearLayout(activity);
    ListView listview = new ListView(activity);
    // setup the mainpanel
    {
      // apply view group params for the activity's root pane
      LayoutUtils.Layout.WidthFill_HeightFill.applyViewGroupParams(mainpanel);
      // set animation layout on the mainpanel
      AnimUtils.setLayoutAnim_slideupfrombottom(mainpanel, activity);
    }

    // setup the listview and add to the mainpanel
    {
      LayoutUtils.Layout.WidthWrap_HeightWrap.applyLinearLayoutParams(listview);

      listview.setAdapter(adapter);

      AnimUtils.setLayoutAnim_slidedownfromtop(listview, activity);

      mainpanel.addView(listview);
    }

    // return the mainpanel
    return mainpanel;
  }

  public static View newLinearPanel(Activity context, View ... views) {
    LinearLayout panel = new LinearLayout(context);
    for (View v : views) {
      panel.addView(v);
    }
    return panel;
  }

  public static View newTextView(Context context, String text) {
    TextView view = new TextView(context);
    view.setText(text);
    view.setTextSize(15);
    return view;
  }
}
